package org.pp.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.pp.admin.dto.SysMenuAdd;
import org.pp.admin.dto.SysMenuEdite;
import org.pp.annotations.Permission;
import org.pp.core.PageBean;
import org.pp.core.Result;
import org.pp.dto.PageDto;
import org.pp.entity.SysMenu;
import org.pp.service.ISysMenuService;
import org.pp.vo.AdminMenuTreeVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 权限（菜单） 前端控制器
 * </p>
 *
 * @author haima
 * @since 2024-04-16
 */
@RestController
@RequestMapping("/sys/menu")
public class SysMenuController extends
        BaseCrudController<SysMenu,SysMenuAdd, SysMenuEdite,SysMenu>
implements BaseAdd<SysMenuAdd>,
        BaseEdite<SysMenuEdite>,
        BaseDetail<SysMenu>,
        BasePage<SysMenu>,
        BaseDelete
{
    @Autowired
    ISysMenuService sysMenuService;


    @Override
    @Permission("post:/sys/menu/add")
    public Result<Object> add(SysMenuAdd dto) {
        return super.add(dto);
    }

    @Override
    @Permission("post:/sys/menu/delete")
    public Result<Void> delete(String ids) {
       // return super.delete(ids);
        sysMenuService.delete(ids);
        return Result.ok();
    }

    @Override
    @Permission("post:/sys/menu/edite")
    public Result<Void> edite(SysMenuEdite dto) {
        return super.edite(dto);
    }

    @Override
    public Result<SysMenu> detail(Long id) {
        return super.detail(id);
    }

    @GetMapping("/tree")
    @Permission("get:/sys/menu/tree")
    @Operation(summary = "返回菜单（树形结构）")
    public Result<List<AdminMenuTreeVo>> tree(){
        List<AdminMenuTreeVo> list= sysMenuService.tree();
        return Result.ok(list);
    }
}